package com.summer.data.jql.concept.exp;

import com.summer.data.Jsql;
import com.summer.data.dialect.Dialect;
import com.summer.data.jql.Context;
import com.summer.data.jql.behavior.OrderAble;
import com.summer.data.jql.concept.Field;

/**
 * @author 345480567@qq.com
 */

public class OrderExp implements OrderAble {

    public enum ORDER_TYPE {
        ASC, DESC
    }

    Field exp;

    ORDER_TYPE order;

    public OrderExp(Field exp) {
        this.exp = exp;
        order = ORDER_TYPE.ASC;
    }

    public OrderExp(Field exp, ORDER_TYPE order) {
        this.exp = exp;
        this.order = order;
    }

    @Override
    public Jsql toOrderSql(Context ctx, Dialect dialect) {
        return Jsql.format("%s %s", exp.toFieldSql(ctx, dialect), order);
    }

}
